﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Vision.Common.Common
{
    class MatrixEx
    {
        /// <summary>
        /// 获取指定矩形边框
        /// </summary>
        /// <param name="loc"></param>
        /// <param name="size"></param>
        /// <param name="angle"></param>
        /// <returns></returns>
        static public Rectangle GetBoard(Point loc,Size size,float angle)
        {
            Matrix m = new Matrix();
            m.Translate(loc.X, loc.Y);
            m.Rotate(angle);
            PointF[] pts = new PointF[3];
            pts[0] = new PointF(size.Width, 0);
            pts[1] = new PointF(size.Width, size.Height);
            pts[2] = new PointF(0, size.Height);
            m.TransformPoints(pts);
            float minX = loc.X, maxX = loc.X, minY = loc.Y, maxY = loc.Y;
            for(int i=0;i<3;i++)
            {
                minX = Math.Min(minX, pts[i].X);
                maxX = Math.Max(maxX, pts[i].X);
                minY = Math.Min(minY, pts[i].Y);
                maxY = Math.Max(maxY, pts[i].Y);
            }
            Rectangle rect = Rectangle.FromLTRB((int)minX, (int)minY, (int)maxX, (int)maxY);
            return rect;
        }
    }
}
